package com.eeds.controller.pc;

import com.eeds.base.BaseController;
import com.eeds.common.constant.ParametersConstants;
import com.eeds.common.model.BaseWrapper;
import com.eeds.common.model.PageInfo;
import com.eeds.interceptor.NeedAuth;
import com.eeds.model.user.req.*;
import com.eeds.model.user.res.ResGetUserInfoListVO;
import com.eeds.model.user.res.ResGetUserInfoVO;
import com.eeds.model.user.res.ResLoginVo;
import com.eeds.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Flying
 * @Description
 * @date 14:16 2018-08-24
 **/
@RestController
@Api(value = "用户接口", description = "用户接口")
@RequestMapping("pc/user/")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;




    @ApiOperation("登陆接口")
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public BaseWrapper<ResLoginVo> login(@Valid @ModelAttribute ReqLoginVo reqLoginVo){
        ResLoginVo result = userService.login(reqLoginVo);
        return new BaseWrapper<>(result);
    }

    @ApiOperation("登陆PC接口")
    @RequestMapping(value = "/loginPC", method = RequestMethod.GET)
    public BaseWrapper<ResLoginVo> loginPC(@Valid @ModelAttribute ReqLoginVo reqLoginVo){
        ResLoginVo result = userService.loginPC(reqLoginVo);
        return new BaseWrapper<>(result);
    }

    /**
     * description:修改用户信息
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST,headers = {ParametersConstants.ACCESS_TOKEN})
    @ApiOperation("修改用户信息")
    public BaseWrapper<Integer> updateUserInfo(@Valid @ModelAttribute ReqUpdateUserInfoVO reqUpdateUserInfoVO){
        Integer result = userService.updateUserInfo(reqUpdateUserInfoVO);
        return new BaseWrapper<>(result);
    }

    /**
     * description:添加用户信息
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/addUserInfo", method = RequestMethod.POST)
    @ApiOperation("添加用户信息")
    public BaseWrapper<Integer> addUserInfo(@Valid @ModelAttribute ReqAddUserInfoVO reqAddUserInfoVO){
        Integer result = userService.addUserInfo(reqAddUserInfoVO);
        return new BaseWrapper<>(result);
    }

    /**
     * description:获取用户信息列表
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/getUserInfoList", method = RequestMethod.GET)
    @ApiOperation("获取用户信息列表")
    public BaseWrapper<PageInfo<ResGetUserInfoListVO>> getUserInfoList(
            @Valid @ModelAttribute ReqGetUserInfoListVO reqGetUserInfoListVO){
        PageInfo<ResGetUserInfoListVO> result = userService.getUserInfoList(reqGetUserInfoListVO);
        return new BaseWrapper<>(result);
    }

    /**
     * description:删除用户
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/deleteUser", method = RequestMethod.POST)
    @ApiOperation("删除用户")
    public BaseWrapper<Integer> deleteUser(@Valid @ModelAttribute ReqDeleteUserVO reqDeleteUserVO){
        Integer result = userService.deleteUser(reqDeleteUserVO);
        return new BaseWrapper<>(result);
    }

    /**
     * description:修改用户密码
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/updateUserPassword", method = RequestMethod.POST)
    @ApiOperation("修改用户密码")
    public BaseWrapper<Integer> updateUserPassword(@Valid @ModelAttribute ReqUpdateUserPasswordVO reqUpdateUserPasswordVO){
        Integer result = userService.updateUserPassword(reqUpdateUserPasswordVO);
        return new BaseWrapper<>(result);
    }

    /**
     * description:重置用户密码
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/resetUserPassword", method = RequestMethod.POST)
    @ApiOperation("重置用户密码")
    public BaseWrapper<Integer> resetUserPassword(@Valid @ModelAttribute ReqResetUserPasswordVO reqResetUserPasswordVO){
        Integer result = userService.resetUserPassword(reqResetUserPasswordVO);
        return new BaseWrapper<>(result);
    }



    /**
     * description:获取用户信息
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.GET)
    @ApiOperation("获取用户信息")
    public BaseWrapper<ResGetUserInfoVO> getUserInfo(@Valid @ModelAttribute ReqGetUserInfoVO reqGetUserInfoVO){
        ResGetUserInfoVO result = userService.getUserInfo(reqGetUserInfoVO);
        return new BaseWrapper<>(result);
    }

    /**
     * description:获取用户信息所有列表
     * @author: Flying
     * @date: 2018-08-28 12:31
     * @param: null
     * @return
     */
    @NeedAuth(role = 1)
    @RequestMapping(value = "/getUserInfoListAll", method = RequestMethod.GET)
    @ApiOperation("获取用户信息所有列表")
    public BaseWrapper<List<ResGetUserInfoListVO>> getUserInfoListAll(){
        List<ResGetUserInfoListVO> result = userService.getUserInfoListAll();
        return new BaseWrapper<>(result);
    }

}
